home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk52 / oneplane / oneplane.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  4KB  |  132 lines

  1. /*
  2.  
  3.  OnePlane.c - program to steal bottom bitplane from workbench screen
  4.  
  5. Ethan Dicks
  6. (c) 15-Nov-1988
  7.  
  8. Version 1.1
  9. (c) 14-Dec-1988
  10.  
  11. This progam is *not* in the public domain, but may be freely redistributed on
  12. the condition that it is not sold, nor used in any commercial or shareware
  13. package without express written permission of the author.  This program may
  14. be included in a freely redistributable library, including, but not limited
  15. to the Fred Fish library collection.  In other words, selling this program
  16. is right out, but giving it away is encouraged.
  17.  
  18. I got the encouragement for this program from the discussion on comp.sys.amiga
  19. regarding fast text scrolling.  Someone called for a program to reduce the
  20. Workbench screen to 1 bitplane to enhance the speed of CON: output.
  21.  
  22. COMPILATION INSTUCTIONS:
  23.  
  24. This code will compile under either Lattice C, V4.01 or V5.00, although
  25. V5.00 will produce a 28 byte smaller executable.  Currently, Lattice V4.01
  26. produces a 468 byte executable, and V5.00 produces a 440 byte executable.
  27. Who says C has to be bloated!
  28.  
  29. To compile, either use LMK and the provided Makefile or use the commands:
  30.  
  31. lc -b0 -v oneplane.c
  32. blink oneplane.o SC SD ND
  33.  
  34. This is why some of the structure looks odd; I don't link with any external
  35. files, not even startup code.  I know that the program could be made even
  36. smaller, but what do want for a one night's hack?
  37.  
  38.  
  39. HOW IT WORKS:
  40.  
  41. In the structure GfxBase, there is a field, ActView, which describes the 
  42. current ViewPort.  This program uses the active viewport information to
  43. aquire the active BitPlane structure, which contains information about how
  44. many bitplanes are in use, their location in memory, the number of rows in
  45. the bitplane, and the number of bytes in each row.  With this information,
  46. is it trival to change the number of bitplanes down by one, and to free
  47. up the memory held by the highest bitplane.  The request is checked in case
  48. this is the only bitplane allocated.  The advantage of this system is that
  49. the number of bitplanes can be increased and decreased at will, without
  50. fear of a visit from the GURU.
  51.  
  52. Most of the information I got came from the RKM graphic primitives section,
  53. in the Libraries and Devices volume, especially the examples, and most of the
  54. rest came from picking apart the include files.
  55.  
  56. */
  57.  
  58. #include <exec/types.h>
  59. #include <exec/execbase.h>
  60. #include <intuition/intuition.h>
  61. #include <graphics/gfxbase.h>
  62. #include <proto/exec.h>
  63. #include <proto/intuition.h>
  64. #include <proto/graphics.h>
  65.  
  66. #define MIN_DEPTH 1
  67.  
  68.  
  69. #pragma libcall ExecBase FreeMem d2 0902
  70. #pragma libcall IntuitionBase RemakeDisplay 180 00
  71. #pragma libcall ExecBase CloseLibrary 19e 901
  72. #pragma libcall ExecBase OpenLibrary 228 0902
  73.  
  74. struct View *currentview;    /* pointer to active View */
  75. struct ViewPort *currentvp;    /* pointer to active ViewPort */
  76. struct RasInfo *currentri;    /* pointer to active RasInfo */
  77. struct BitMap *b;        /* pointer to current BitMap */
  78.  
  79. /* struct Execbase *ExecBase; */
  80. struct GfxBase *GfxBase;
  81. struct IntuitionBase *IntuitionBase;
  82. struct ExecBase *ExecBase, **EBase;
  83.  
  84.  
  85.  
  86. /* 
  87.     Here goes nuthin'
  88. */
  89. void main()
  90.  
  91. {
  92. /* Set the ExecBase pointer manually, since we do not link with anybody */
  93.     EBase = (struct ExecBase **)(4L);
  94.     ExecBase = *EBase;
  95.  
  96. /* Open the graphics.library and the intuition.library */
  97.  
  98. /* error checking not done, because if they won't open, the system is hosed */
  99.     GfxBase
  100.         = (struct GfxBase *)OpenLibrary("graphics.library",0);
  101.  
  102.     IntuitionBase
  103.         = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  104.  
  105. /* Here goes with the pointer game... the idea is to end up at the BitMap */
  106.  
  107.     currentview = GfxBase -> ActiView;    /* get current View */
  108.     currentvp = currentview -> ViewPort;    /* get current ViewPort */
  109.     currentri = currentvp -> RasInfo;    /* get current RasInfo */
  110.     b      = currentri -> BitMap;        /* get current BitMap */
  111.  
  112. /* And here is where we fiddle with the numbers */
  113.  
  114. /* ---> ONLY DO THIS IF THERE ARE BITPLANES LEFT TO REMOVE <--- */
  115.     if ( (b -> Depth) > MIN_DEPTH) {
  116.  
  117.         b -> Depth -= 1;
  118.         FreeMem( (b -> Planes)[(b -> Depth)],
  119.              (b-> Rows) * (b -> BytesPerRow) );
  120.  
  121.     }
  122.  
  123. /* Now that we are done fiddling with it, redraw the display */
  124.     RemakeDisplay();
  125.     
  126. /* Now clean up and go home */
  127.     CloseLibrary((struct Library *)GfxBase);
  128.     CloseLibrary((struct Library *)IntuitionBase);
  129. }
  130.  
  131. void MemCleanUp(){}
  132.